"""
多窗口操作 点击打开一个新的窗口
window_handles 获取多个窗口，返回一个窗口的列表
current_window_handle 获取当前窗口
switch_to.window(str)切换到其他窗口
"""


import time

from  selenium import webdriver
from  selenium.webdriver.common.by import By

# 获取驱动
driver = webdriver.Edge()
# 通过驱动打开网页
driver.get("http://www.baidu.com")
time.sleep(1)

# 获取多个a标签
aelements = driver.find_elements("class name","mnav.c-font-normal.c-color-t")
# 点击多个a标签
for a in aelements:
    a.click()

# 获取所有的窗口
window_list = driver.window_handles
for i in window_list:
    print(type(i),"----")
    print(i)

# 获取当前窗口
c = driver.current_window_handle
print("当前窗口",c)
print("当前窗口的标题",driver.title)

time.sleep(5)
# 切换到某个窗口
driver.switch_to.window(window_list[3])
print("切换后窗口的标题",driver.title)

time.sleep(10)

